//
//  CommentsController.m
//  敢唆嘛!
//
//  Created by 教主 on 15/11/26.
//  Copyright © 2015年 zms. All rights reserved.
//

#import "CommentsController.h"
#import "Device.h"
#import "CommentsCell.h"
#import "CommentsModel.h"
#import "ChineseToPinyin.h"
#import "CommentsHeader.h"

@interface CommentsController () <UITableViewDataSource, UITableViewDelegate, UITextViewDelegate>
@property(nonatomic, strong)UITableView *commentsTableVew;  //tableview视图
@property(nonatomic, strong)NSMutableArray *commentsArray;   //评论数组
@property(nonatomic, strong)UITextView *commentsTextView;   //输入
@property(nonatomic, strong)UIView *shadow;                 // 阴影
@property(nonatomic, strong)UIView *commentsView;          // 键盘上方的View
@property(nonatomic, strong)UILabel *placeHolderLabel;  // 占位符
@property(nonatomic, strong)BmobUser *bmobUser;         // 用户
@property(nonatomic, strong)NSString *targetUserName;       // 目标用户名字
@end

static NSString *cellIdentifier = @"comments";
@implementation CommentsController
{
    NSInteger limitNumber;  // 分页查询记录
}

// 查询bmob数据库表内所有内容 最多1000 默认100
- (void)findAllCommentsData:(NSInteger)limit
{
    NSString *infoTitle = nil;
    if (self.homeModel)
    {
        infoTitle = self.homeModel.infoTitle;
    }
    else
    {
        infoTitle = self.realityModel.infoTitle;
    }
    // 把主题转化为拼音
    NSString *string = [ChineseToPinyin pinyinFromChiniseString:infoTitle];
    //根据主题名称查询一个该主题单独的评论表

    BmobQuery *bquery = [BmobQuery queryWithClassName:[NSString stringWithFormat:@"%@Comments",string]];
    [bquery orderByDescending:@"createdAt"];
    bquery.limit = limit;
    //查找数据
    [bquery findObjectsInBackgroundWithBlock:^(NSArray *array, NSError *error) {
        if (error)
        {
            // 判断网络连接
            if (![[NetWorkState shareInstance] reachability])
            {
                [self alertActionWithTitle:@"提示" message:@"网络不通" other:@"确定"];
            };
            NSLog(@"error:%@",error);
            [self.commentsTableVew.header endRefreshing];
        }
        else
        {
            // 数据请求成功后才初始化数组 否则会造成下拉刷新崩溃
            self.commentsArray = [NSMutableArray array];
            for (BmobObject *obj in array)
            {
                CommentsModel *model = [[CommentsModel alloc] initWithObj:obj];
                // 条用多条查询 来获取多个用户头像
                [self findUserDataWith:model];
                [self.commentsArray addObject:model];
            }
            // 需要在主线程里面进行刷新
            dispatch_async(dispatch_get_main_queue(), ^{
                [self.commentsTableVew reloadData];
                [self.commentsTableVew.header endRefreshing];
                [self.commentsTableVew.footer endRefreshing];
            });
        }
    }];
}

// 查询bmob数据库表内所有内容 最多1000 默认100  查找用户
- (void)findUserDataWith:(CommentsModel *)model
{
    BmobQuery *bquery = [BmobQuery queryWithClassName:@"_User"];
    bquery.limit = 1000;
    //查找Recommend表的数据
    [bquery findObjectsInBackgroundWithBlock:^(NSArray *array, NSError *error) {
        if (error)
        {
            // 判断网络连接
            if (![[NetWorkState shareInstance] reachability])
            {
                [self alertActionWithTitle:@"提示" message:@"网络不通" other:@"确定"];
            };
            NSLog(@"error:%@",error);
        }
        else
        {
            for (BmobObject *obj in array)
            {
                if ([model.userName isEqualToString:[obj objectForKey:@"username"]])
                {
                    BmobFile *userHeaderFile = [obj objectForKey:@"userHeader"];
                    model.userHeader = userHeaderFile.url;
                }
            }
            // 需要在主线程里面进行刷新
            dispatch_async(dispatch_get_main_queue(), ^{
                [self.commentsTableVew reloadData];
            });
        }
    }];
}


- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationController.navigationBar.translucent = NO;
    self.view.backgroundColor = [UIColor whiteColor];
    
    CGFloat sy = KSWidth / 28;
    
    // 添加标题
    UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0 , 0, KSWidth / 8, KSWidth / 28)];
    titleLabel.text = @"评论";
    titleLabel.alpha = 0.8;
    titleLabel.textAlignment = NSTextAlignmentCenter;
    titleLabel.font = [UIFont systemFontOfSize:KSWidth / 22];
    self.navigationItem.titleView = titleLabel;
    
    // 添加左上角返回按钮
    UIButton *backBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    backBtn.frame = CGRectMake(0, 0, KSWidth / 18, KSWidth / 18);
    [backBtn setImage:[UIImage imageNamed:@"iconfont-unie61e"] forState:UIControlStateNormal];
    [backBtn addTarget:self action:@selector(backBtnAction:) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem *leftBackBtn = [[UIBarButtonItem alloc] initWithCustomView:backBtn];
    self.navigationItem.leftBarButtonItem = leftBackBtn;
    
    // 添加右上角添加按钮
    UIButton *addBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    addBtn.frame = CGRectMake(0, 0, KSWidth / 15, KSWidth / 15);
    [addBtn setImage:[UIImage imageNamed:@"iconfont-iconfontpinglun"] forState:UIControlStateNormal];
    [addBtn addTarget:self action:@selector(addBtnAction:) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem *rightBackBtn = [[UIBarButtonItem alloc] initWithCustomView:addBtn];
    self.navigationItem.rightBarButtonItem = rightBackBtn;
    
    self.commentsTableVew = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, KSWidth, KSHeight - 64) style:UITableViewStyleGrouped];
    self.commentsTableVew.delegate = self;
    self.commentsTableVew.dataSource = self;
    self.commentsTableVew.backgroundColor = [UIColor whiteColor];
    //注册cell
    [self.commentsTableVew registerClass:[CommentsCell class] forCellReuseIdentifier:cellIdentifier];
    //注册表头
    [self.commentsTableVew registerClass:[CommentsHeader class] forHeaderFooterViewReuseIdentifier:@"header"];
    [self.view addSubview:_commentsTableVew];
    
    // 创建阴影
    self.shadow = [[UIView alloc] initWithFrame:self.view.frame];
    self.shadow.backgroundColor = [UIColor blackColor];
    self.shadow.alpha = 0.4;
    self.shadow.hidden = YES;
    [self.view addSubview:_shadow];
    
    // 创建键盘上方的输入View
    self.commentsView = [[UIView alloc] initWithFrame:CGRectMake(0, -KSHeight, KSWidth, KSHeight / 12)];
    self.commentsView.backgroundColor = [UIColor whiteColor];
    // 阴影层
    self.commentsView.layer.shadowOffset = CGSizeMake(0, 3);
    self.commentsView.layer.shadowRadius = 5.0;
    self.commentsView.layer.shadowColor = [UIColor blackColor].CGColor;
    self.commentsView.layer.shadowOpacity = 0.8;
    
    self.commentsTextView = [[UITextView alloc] initWithFrame:CGRectMake(sy, sy, KSWidth - sy * 2, KSWidth / 11.2)];
    self.commentsTextView.font = [UIFont systemFontOfSize:KSWidth / 25];
    self.commentsTextView.delegate = self;
//    self.commentsTextView.backgroundColor = [UIColor redColor];
//    self.commentsTextView.inputAccessoryView = _commentsView;
    // 更改键盘return
    self.commentsTextView.returnKeyType = UIReturnKeySend;
    [self.commentsView addSubview:_commentsTextView];
    
    // 创建占位符
    self.placeHolderLabel = [[UILabel alloc] initWithFrame:CGRectMake(sy / 2, sy / 2 / 2, KSWidth, KSWidth / 14)];
    self.placeHolderLabel.text = @"输入评论吧~";
    self.placeHolderLabel.textColor = [UIColor colorWithRed:160 / 255.0 green:160 / 255.0 blue:160 / 255.0 alpha:1.0];
    self.placeHolderLabel.font = [UIFont systemFontOfSize:KSWidth / 25];
    self.placeHolderLabel.enabled = NO;
    [self.commentsTextView addSubview:_placeHolderLabel];
    
//    UIView *blackLine = [[UIView alloc] initWithFrame:CGRectMake(sy, _commentsTextView.frame.size.height + sy / 2, _commentsTextView.frame.size.width, 1)];
//    blackLine.backgroundColor = [UIColor blackColor];
//    blackLine.alpha = 0.1;
//    [self.commentsView addSubview:blackLine];
    [self.view addSubview:_commentsView];
    
    // 默认 10个
    limitNumber = 10;
    // 调用首页数据
    [self findAllCommentsData:limitNumber];
    
    // 添加下拉刷新
    [self.commentsTableVew addLegendHeaderWithRefreshingTarget:self refreshingAction:@selector(headerRefreshing)];
    
    // 添加上拉加载更多
    [self.commentsTableVew addLegendFooterWithRefreshingTarget:self refreshingAction:@selector(footerRefreshing)];
    
//    // 添加键盘弹出的通知
//    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyBoardShow:) name:UIKeyboardWillShowNotification object:nil];
//    
//    // 添加键盘回收的通知
//    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyBoardHide:) name:UIKeyboardWillHideNotification object:nil];
    
//    // 添加键盘frame改变的通知 (相当于切换键盘)
//    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyBoardChange:) name:UIKeyboardDidChangeFrameNotification object:nil];
 
}

// 下拉刷新
- (void)headerRefreshing
{
    // 刷新调用
    [self findAllCommentsData:limitNumber];
}

// 上拉加载更多
- (void)footerRefreshing
{
    limitNumber += 5;
    // 刷新调用
    [self findAllCommentsData:limitNumber];
}



// 添加评论按钮触发
- (void)addBtnAction:(UIButton *)addBtn
{
    [UIView animateWithDuration:0.3 animations:^{
        self.commentsView.frame = CGRectMake(0, 0, KSWidth, KSHeight / 12);
    }];
    
    self.shadow.hidden = NO;
    // 调出键盘
    [_commentsTextView becomeFirstResponder];
    [self.navigationController.navigationBar setBarTintColor:[UIColor colorWithRed:160 / 255.0 green:160 / 255.0 blue:160 / 255.0 alpha:1.0]];
}

// 点击空白回收键盘
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
    [UIView animateWithDuration:0.3 animations:^{
        self.commentsView.frame = CGRectMake(0, -KSHeight, KSWidth, KSHeight / 12);
    }];
    [_commentsTextView resignFirstResponder];
    self.shadow.hidden = YES;
    [self.navigationController.navigationBar setBarTintColor:[UIColor whiteColor]];
    _placeHolderLabel.text = @"输入评论吧~";
    self.commentsTextView.text = @"";
    self.targetUserName = nil;
}

- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text
{
    // 如果按了send 就回收键盘并且发送
    if ([text isEqualToString:@"\n"])
    {
        if (_commentsTextView.text.length == 0)
        {
            // 不能为空
            return NO;
        }
        else
        {
            self.shadow.hidden = YES;
            [UIView animateWithDuration:0.3 animations:^{
                self.commentsView.frame = CGRectMake(0, -KSHeight, KSWidth, KSHeight / 12);
            }];
            [self.navigationController.navigationBar setBarTintColor:[UIColor whiteColor]];
            // 把评论存储到数据库
            [self addCOmmentsData];
            
            return [_commentsTextView resignFirstResponder];
        }
    }
    else
    {
        _placeHolderLabel.text = @"";
        return YES;
    }
}

// 点击cell
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    CommentsModel *model = self.commentsArray[indexPath.row];
    // 获取当前登录的用户
    self.bmobUser = [BmobUser getCurrentUser];
    if (![model.userName isEqualToString:_bmobUser.username])
    {
        [UIView animateWithDuration:0.3 animations:^{
            self.commentsView.frame = CGRectMake(0, 0, KSWidth, KSHeight / 12);
        }];
        self.shadow.hidden = NO;
        // 每次点击cell 保存当前所点击的用户名称
        self.targetUserName = model.userName;
        
        _placeHolderLabel.text = [NSString stringWithFormat:@"回复''%@'':",model.userName];
        // 调出键盘
        [_commentsTextView becomeFirstResponder];
    }
    else
    {
        CommentsCell *cell = (CommentsCell *)[self.commentsTableVew cellForRowAtIndexPath:indexPath];
        [self promptViewWithTitle:@"不能跟自己回复哟~" buttonEnabled:nil cellUser:cell];
    }

}

//// 查询单条 真事
//- (void)getRealityData
//{
//    NSString *realityObjectId = nil;
//    NSInteger recommendNumber = 0;
//    NSInteger collectNumber = 0;
//    if (self.homeModel)
//    {
//        realityObjectId = self.homeModel.realityObjectId;
//        recommendNumber =
//        collectNumber
//    }
//    else
//    {
//        realityObjectId = self.realityModel.objectId;
//    }
//    //查找Reality表单条数据
//    BmobQuery *bquery = [BmobQuery queryWithClassName:@"Reality"];
//    [bquery getObjectInBackgroundWithId:realityObjectId block:^(BmobObject *object,NSError *error){
//        if (error)
//        {
//            // 判断网络连接
//            if (![[NetWorkState shareInstance] reachability])
//            {
//                [self alertActionWithTitle:@"提示" message:@"网络不通" other:@"确定"];
//            };
//            NSLog(@"error:%@",error);
//        }
//        else
//        {
//            //表里有id为model.realityObjectId的数据
//            if (object)
//            {
//                model.recommendNumber = [[object objectForKey:@"recommendNumber"] integerValue];
//                model.collectNumber = [[object objectForKey:@"collectNumber"] integerValue];
//            }
//            // 需要在主线程里面进行刷新
//            dispatch_async(dispatch_get_main_queue(), ^{
//                [self.homeTableView reloadData];
//            });
//        }
//    }];
//}


// 根据主题名称生成表存入用户和评论数据
- (void)addCOmmentsData
{
    NSString *infoTitle = nil;
    
    if (self.homeModel)
    {
        infoTitle = self.homeModel.infoTitle;
    }
    else
    {
        infoTitle = self.realityModel.infoTitle;
    }
    
    // 获取当前登录的用户
    self.bmobUser = [BmobUser getCurrentUser];
    // 把主题转化为拼音
    NSString *string = [ChineseToPinyin pinyinFromChiniseString:infoTitle];
    //根据主题名称添加一个该主题单独的评论表
    BmobObject *comments = [BmobObject objectWithClassName:[NSString stringWithFormat:@"%@Comments",string]];
    [comments setObject:_bmobUser.username forKey:@"userName"];
    [comments setObject:self.commentsTextView.text forKey:@"userComments"];
    [comments setObject:infoTitle forKey:@"infoTitle"];
    // 证明是点击了cell需要回复别人的,所以添加目标用户
    [comments setObject:self.targetUserName forKey:@"targetUserName"];
    
    [comments saveInBackgroundWithResultBlock:^(BOOL isSuccessful, NSError *error) {
        //进行操作
        if (isSuccessful)
        {
            NSLog(@"评论保存成功");
            // 弹出对话框提示
            [self promptViewWithTitle:@"发布成功咯~" buttonEnabled:self.navigationItem.rightBarButtonItem cellUser:nil];
            // textView内容滞空
            self.commentsTextView.text = @"";
            _placeHolderLabel.text = @"输入评论吧~";
            
            // 刷新调用
            [self findAllCommentsData:limitNumber];
            
            // 更新 reality表内的指定主题的评论数
            [self updateRealityTableComments];
        }
        else
        {
            NSLog(@"评论保存失败");
            NSLog(@"%@",error);
            [self promptViewWithTitle:@"评论失败咯~" buttonEnabled:self.navigationItem.rightBarButtonItem cellUser:nil];
        }
    }];
}

// 返回是哪个表的数据
- (NSString *)tableClassName
{
    NSString *className = nil;
#warning 判断页面
    if (self.homeModel)
    {
        if ([self.homeModel.type isEqualToString:@"真事"])
        {
            className = @"Reality";
        }
        else if ([self.homeModel.type isEqualToString:@"创作"])
        {
            className = @"Creation";
        }
        else if ([self.homeModel.type isEqualToString:@"游记"])
        {
            className = @"Travel";
        }
        else if ([self.homeModel.type isEqualToString:@"秘密"])
        {
            className = @"Secret";
        }
    }
    else
    {
        if ([self.realityModel.type isEqualToString:@"真事"])
        {
            className = @"Reality";
        }
        else if ([self.realityModel.type isEqualToString:@"创作"])
        {
            className = @"Creation";
        }
        else if ([self.realityModel.type isEqualToString:@"游记"])
        {
            className = @"Travel";
        }
        else if ([self.realityModel.type isEqualToString:@"秘密"])
        {
            className = @"Secret";
        }
    }
    return className;
}

// 更新 reality表内的指定主题的评论数
- (void)updateRealityTableComments
{
    NSString *commentObjectId = nil;
    if (self.homeModel)
    {
        commentObjectId = self.homeModel.realityObjectId;
    }
    else
    {
        commentObjectId = self.realityModel.objectId;
    }

    // 先获取到本来的收藏数是多少
    BmobQuery *bquery = [BmobQuery queryWithClassName:[self tableClassName]];
    [bquery getObjectInBackgroundWithId:commentObjectId block:^(BmobObject *object,NSError *error){
        if (error){
            //进行错误处理
        }else{
            if (object)
            {
                // 得到该条数据当前的收藏数是多少
                NSInteger number = [[object objectForKey:@"commentNumber"] integerValue] + 1;
                NSNumber *recommendNumber = [NSNumber numberWithInteger:number];
                // 修改值
                BmobObject *bmobObject = [BmobObject objectWithoutDatatWithClassName:[self tableClassName]  objectId:commentObjectId];
                [bmobObject setObject:recommendNumber forKey:@"commentNumber"];
                [bmobObject updateInBackgroundWithResultBlock:^(BOOL isSuccessful, NSError *error) {
                    if (isSuccessful) {
                        //修改成功后的动作
                        NSLog(@"评论数更新+1");
                    } else if (error){
                        NSLog(@"%@",error);
                    } else {
                        NSLog(@"UnKnow error");
                    }
                }];
            }
        }
    }];
}


// 返回按钮触发
- (void)backBtnAction:(UIButton *)backBtn
{
    // 执行完通知的方法之后 要进行移除通知
    [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillShowNotification object:nil];
    [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillHideNotification object:nil];
    [self.navigationController popViewControllerAnimated:YES];
}

// 返回cell
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    CommentsCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier forIndexPath:indexPath];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    
    if (self.commentsArray.count == 0)
    {
        cell.promptLabel.hidden = NO;
    }
    else
    {
        cell.promptLabel.hidden = YES;
    }
    
    [cell setCommentsModel:self.commentsArray[indexPath.row]];
    
    // 滞空,否则永远是有用户存在的 只有在点击cell的时候才知道是不是要对这个用户发表评论
    self.targetUserName = nil;
    
    return cell;
}

// 返回表头cell
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    CommentsHeader *header = [tableView dequeueReusableHeaderFooterViewWithIdentifier:@"header"];
    if (self.homeModel)
    {
        [header setHomeModel:self.homeModel];
    }
    else
    {
        [header setRealityModel:self.realityModel];
    }

    return header;
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (_commentsArray.count == 0)
    {
        return 1;
    }
    else
    {
        return self.commentsArray.count;
    }
}

// 返回表头高度
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    CGFloat height = (KSWidth / 20) * 2 + (KSWidth / 14) * 2;
    return height;
}

// 返回表尾高度
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return 0.01;
}

// 返回cell高度
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (self.commentsArray.count == 0)
    {
        return 0;
    }
    else
    {
        return [CommentsCell heightForCell:self.commentsArray[indexPath.row]];
    }
}


// 弹出视图
- (void)alertActionWithTitle:(NSString *)title message:(NSString *)message other:(NSString *)other
{
    UIAlertController *alertVc = [UIAlertController alertControllerWithTitle:title message:message preferredStyle:UIAlertControllerStyleAlert];
    UIAlertAction *otherAction = [UIAlertAction actionWithTitle:other style:UIAlertActionStyleDefault handler:nil];
    [alertVc addAction:otherAction];
    [self presentViewController:alertVc animated:YES completion:nil];
}

// 弹出提示窗口
- (void)promptViewWithTitle:(NSString *)title buttonEnabled:(UIBarButtonItem *)buttonEnabled cellUser:(CommentsCell *)cellUser
{
    // 关闭按钮交互
    cellUser.userInteractionEnabled = NO;
    buttonEnabled.enabled = NO;
    UIView *promptView = [[UIView alloc] initWithFrame:CGRectMake(((KSWidth - (KSWidth / 2)) / 2) * 2, 0, KSWidth / 2, KSWidth / 4)];
    promptView.backgroundColor = [UIColor whiteColor];
    promptView.alpha = 0;
    promptView.layer.cornerRadius = 10;
    promptView.layer.borderColor = [UIColor colorWithRed:150 / 255.0 green:150 / 255.0 blue:150 / 255.0 alpha:1.0].CGColor;
    promptView.layer.borderWidth = 1;
    UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(((KSWidth - (KSWidth / 2)) / 2) * 2, 0, KSWidth / 2, KSWidth / 4)];
    titleLabel.text = title;
    titleLabel.textAlignment = NSTextAlignmentCenter;
    titleLabel.textColor = [UIColor blackColor];
    titleLabel.font = [UIFont systemFontOfSize:KSWidth / 25];
    titleLabel.alpha = 0;
    [self.view addSubview:promptView];
    [self.view addSubview:titleLabel];
    
    [UIView animateWithDuration:0.4 animations:^{
        promptView.alpha = 0.8;
        titleLabel.alpha = 0.8;
        promptView.frame = CGRectMake((KSWidth - (KSWidth / 1.2)) / 2, KSWidth - KSWidth / 1.35, KSWidth / 1.2, KSWidth / 4);
        titleLabel.frame = CGRectMake((KSWidth - (KSWidth / 1.2)) / 2, KSWidth - KSWidth / 1.35, KSWidth / 1.2, KSWidth / 4);
    }completion:^(BOOL finished) {
        // 延迟一秒
        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.8 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
            [UIView animateWithDuration:0.4 animations:^{
                promptView.alpha = 0;
                titleLabel.alpha = 0;
                promptView.frame = CGRectMake(((KSWidth - (KSWidth / 2)) / 2) * 2, 0, KSWidth / 2, KSWidth / 4);
                titleLabel.frame = CGRectMake(((KSWidth - (KSWidth / 2)) / 2) * 2, 0, KSWidth / 2, KSWidth / 4);
            }completion:^(BOOL finished) {
                // 打开收藏按钮交互
                buttonEnabled.enabled = YES;
                cellUser.userInteractionEnabled = YES;
                [promptView removeFromSuperview];
                [titleLabel removeFromSuperview];
            }];
        });
    }];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
